
import { defineStore } from 'pinia'
import { getInfo, logout } from '@/api/login'
import { removeToken } from '@/utils/auth'

export default defineStore("user", {
    state : () => ({
        info: {},
        roles: [],
        permissions: [],
        realm : '',
    }),
    actions : {
        login(){

        },
        getInfo(){
            return new Promise((resolve, reject) => {
                getInfo().then(res => {
                    this.realm = res.data.realm
                })
            })
        },
        logOut(){
            return new Promise((resolve, reject) => {
                logout().then(res => {
                    removeToken(res)
                    return resolve(res)
                }).catch(err => reject(err))
            })
        }
    }
})